package com.xgpro.pc.manage.controller;

import com.xgpro.common.controller.BaseController;
import com.xgpro.common.exceptions.BusinessRuntimeException;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.pc.manage.service.ImageManageSerivce;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author tx
 * @version 1.0
 * @date 2019/11/24 18:03
 */
@RestController
@RequestMapping("/manage")
@CrossOrigin(allowCredentials="true")
public class ImageManageController extends BaseController {
    @Autowired
    private ImageManageSerivce imageManageSerivce;

    /**
     * 新增轮播图
     * @param multipartFile
     * @return
     */
    @RequestMapping("/insertImage")
    public ResponseResult insertImage(MultipartFile multipartFile){
        try{
            return ResponseResult.ok(imageManageSerivce.insertImage(multipartFile));
        }catch (BusinessRuntimeException e){
            return ResponseResult.failure(e.getErrorCode(),e.getMessage());
        }
    }

    /**
     * 轮播图集合
     * @return
     */
    @RequestMapping("/qryImageManageList")
    public ResponseResult qryImageManageList(){
        return ResponseResult.ok(imageManageSerivce.qryImageManageList());
    }

    /**
     * 删除轮播图
     * @param id
     * @return
     */
    @RequestMapping("/deleteImage")
    public ResponseResult deleteImage(Integer id){
        return ResponseResult.ok(imageManageSerivce.deleteImage(id));
    }
}
